import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/circle/model/CircleModel.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/widget/AvatarWidget.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

import 'model/ContactsModel.dart';

class ContactItem extends StatefulWidget {

  final EdgeInsets padding;
  final ContactInfo? contactInfo;

  const ContactItem(this.contactInfo, {Key? key,
    this.padding = const EdgeInsets.all(0),
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return ContactItemState();
  }
}

class ContactItemState extends BaseState<ContactItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(onTap: () => circleDetail(), child: Padding(padding: EdgeInsets.symmetric(vertical: 10),
      child: Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [
        if (widget.contactInfo?.showRadio == true)
            GestureDetector(onTap: () => { check() }, child: Padding(padding: EdgeInsets.only(top: 8, bottom: 8, right: 10),
                child: widget.contactInfo?.checked == true ? LoadImage('ic_radio_checked_22') : LoadImage('ic_radio_unchecked_22'))),
        if (widget.contactInfo?.showRadio == true) W(7),
        RoundedCornerWidget(width: 40, height: 40, radius: 20, padding: EdgeInsets.all(0),  child:
        AvatarWidget(widget.contactInfo?.cover ?? '', 40, 0, 0), backgroundColor: Colors.white, borderWidth: 0,
        ),
        W(8),
        Expanded(child:
        Column(mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start, children: [

                Text(widget.contactInfo?.title ?? '1111', style: TS(15, C.gray333), maxLines: 1, overflow: TextOverflow.ellipsis,),

              H(3),
              Text(widget.contactInfo?.desc ?? '2222', style: TS(12, C.gray666), maxLines: 1, overflow: TextOverflow.ellipsis)
            ])),
        // Spacer(),
        LoadImage('ic_gray_right_arrow')
      ]),
    ));
  }

  check() {
    print('checked: ${widget.contactInfo?.checked}');
    if (widget.contactInfo?.checked == null) {
      widget.contactInfo?.checked = true;
    } else {
      widget.contactInfo?.checked = !(widget.contactInfo!.checked!);
    }
    setState(() => null);
  }

  circleDetail() { // todo

  }
}